#ifndef COMMONCONSUMER_H
#define COMMONCONSUMER_H
#include <cms/MessageListener.h>
#include <activemq/library/ActiveMQCPP.h>
#include <decaf/lang/Thread.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Long.h>
#include <decaf/lang/System.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <cms/Connection.h>
#include <cms/Session.h>
#include <cms/ExceptionListener.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <memory>
#include "log4qt/logger.h"

#include "commandconfig.h"

class CommonConsumer
{
private:
	cms::Connection* connection;
	cms::Session* session;
	cms::Destination* destination;
	cms::MessageConsumer* consumer;

	CommandConfig* cmdCfg;

	cms::MessageListener* listener; //pass by external

	Log4Qt::Logger* log;
	int refCount;
private:
	CommonConsumer( const CommonConsumer& );
	CommonConsumer& operator= ( const CommonConsumer& );

public:
	CommonConsumer(
		cms::Connection* connection,
		CommandConfig* cmdConfig,
		cms::MessageListener* listener ) ;
	virtual ~CommonConsumer() throw() ;
	void close() ;
	virtual void init()  ;
	const CommandConfig* getCfg() const {return cmdCfg;}
	std::string& getName() const {return cmdCfg->name;}
	void increaseRef(){refCount++;}
	void decreaseRef(){refCount--;}
	int getRefCount(){return refCount;}

private:
	void cleanup();
};
#endif